package video

import (
	"context"
	"module_demo/user-service/rpc/user"
	"strconv"

	"module_demo/video-service/api/internal/svc"
	"module_demo/video-service/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetVideoInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetVideoInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetVideoInfoLogic {
	return &GetVideoInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetVideoInfoLogic) GetVideoInfo(req *types.VideoReq) (resp *types.ViedoInfoResp, err error) {
	//获取前端传递的id
	id := req.Id
	//调用rpc获取用户信息
	u, err := l.svcCtx.UserRpc.GetUser(l.ctx, &user.IdRequest{
		Id: strconv.FormatInt(id, 10),
	})
	if err != nil {
		logx.Errorf("rpc调用失败", err)
	}
	return &types.ViedoInfoResp{
		Id:           id,
		Title:        "xxx视频",
		RegisterTime: u.RegisterTime,
		UserId:       u.Id,
		UserName:     u.Username,
	}, nil
}
